package com.iMusic.businessLogicLayer;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.iMusic.integrationLayer.DBConnection;
import com.iMusic.integrationLayer.DBConnectionManager;

public class Feedback {
	
	private int feedbackId = 0;
	private String Description = "";
	private Date DateCreated = null;
	private DBConnection dbConn = null;
	
	static private DBConnectionManager dbConnMgr = null;
	
	/*
	 * Constructor
	 */
	public Feedback() {
		if (dbConnMgr == null) {
			dbConnMgr = DBConnectionManager.getDBConnectionManager();
		}
		
	}
	
	public boolean submit() throws SQLException {
		
		boolean ret = false;
		
		if (dbConn != null) {
			dbConnMgr.freeDBConnection(dbConn);
		}
		
		dbConn = dbConnMgr.getDBConnection();
		dbConn.connect();
		
		Integer nextFeedbackId = 1;
		ResultSet rs = dbConn.query("SELECT MAX(FeedbackId)+1 FROM FEEDBACK");
		if (rs.next()) {
			nextFeedbackId = rs.getInt(1);
		}
		
		String sqlStmt = "INSERT INTO FEEDBACK (FeedbackId,Description,DateCreated)  " +
		"VALUES (" + nextFeedbackId + ", '" + Description + "', curdate()  )";
		System.out.println(sqlStmt);
		dbConn.execSQL(sqlStmt);
		dbConn.execSQL("commit");
		
		dbConn.disconnect();
		
		ret = true;
		
		return ret;

	}

	public int getFeedbackId() {
		return feedbackId;
	}

	public void setFeedbackId(int feedbackId) {
		this.feedbackId = feedbackId;
	}

	public String getDescription() {
		return Description;
	}

	public void setDescription(String description) {
		Description = description;
	}

	public Date getDateCreated() {
		return DateCreated;
	}

	public void setDateCreated(Date dateCreated) {
		DateCreated = dateCreated;
	}

}
